﻿namespace test3

open System
open System.Management

module hyperv =
    type VMSelector = string * string
    type ScsiSelector = VMSelector * string 
    type ControllerSelector =
        | IdeSelector of VMSelector * int
        | ScsiSelector of ScsiSelector
    type DriveSelector = ControllerSelector * int
        
    type VM = { vmsel:VMSelector; name:string; state:uint32 }

    let new_vm (name:string) : VMSelector = "", ""
    let del_vm (vmsel:VMSelector) = ()
    let list_vm () : VM list = list.Empty 
    let get_vm (vmsel:VMSelector) : VM list = list.Empty

    type Cpu = { vmsel:VMSelector; count:int }
    let get_cpu (vmsel:VMSelector) : Cpu = { vmsel = "", ""; count = 0 }
    let set_cpu (cpu:Cpu) = ()
    
    type Mem = { vmsel:VMSelector; startup:int }
    let get_mem (vmsel:VMSelector) : Mem = { vmsel = "", ""; startup = 0 }
    let set_mem (mem:Mem) = ()

    type Image =
        | Vhd of string
        | Iso of string
    type Drive = { drivesel:DriveSelector; img:Image }
        
    let new_scsi (vmsel:VMSelector) : ScsiSelector = unbox null
    let del_scsi (scsiSel:ScsiSelector) = ()
    let list_scsi (vmsel:VMSelector) : ScsiSelector list = list.Empty
    
    let list_drive (controllersel:ControllerSelector) : Drive list = list.Empty
    let get_drive (drivesel:DriveSelector) : Drive = { drivesel=(IdeSelector(("",""), 0),0); img=Vhd("") }
    let del_drive (drivesel:DriveSelector) = ()
    let set_drive (drive:Drive) = ()


module basic_tests =
    open hyperv

    ManagementPath.DefaultPath.Server <- "vmshark10"
    ManagementPath.DefaultPath.NamespacePath <- "root\\virtualization"


    let ``create and remove vm`` =
        let vmsel = new_vm "testvm1"
        del_vm vmsel                
        ()

    let ``set cpu`` =
        let vmsel = new_vm "testvm2"
        let cpu = get_cpu vmsel
        set_cpu { cpu with count = 1 }
        assert ((get_cpu vmsel).count = 1)
        del_vm vmsel
        ()

    let ``set mem`` =
        let vmsel = new_vm "testvm3"
        let mem = get_mem vmsel
        set_mem { mem with startup = 1024 }
        assert ((get_mem vmsel).startup = 1024 )
        del_vm vmsel
        ()

    [<EntryPoint>]
    let main _ =
        
        0

